# """
# 继承
# 父类：定义类时出现在类名后的括号中
#     默认所有类都继承object  可以省略
#
# 子类
#
# 当调用实例的方法时  先在本身找对应的方法实现  如果找不到  则去父类中找对应的实现
# """
#

class Preson(object):
    """
    当类Person 没有编写__str__时会直接使用父类的__str__
    如果自己定义了__str__ 则使用自己的__str__
    """

    def __init__(self, name, age):
        self.name = name
        self.age = age

    def run(self):
        return f"遇到危险能逃跑"

    def __str__(self):
        return f"名字 {self.name}, 年龄 {self.age}"


class SuperPerson(Preson):
    def __init__(self, name, age, skill):
        super().__init__(name, age)
        self.skill = skill

    def stave(self):
        return f"发动技能'{self.skill}'救人"

    def __str__(self):
        return f"{super().__str__()},技能是'{self.skill}'"


p1 = Preson("张三", 40)
print(p1, p1.run())

sp1 = SuperPerson("钢铁侠", 30, "战甲合体")
print(sp1, sp1.run(), sp1.stave())


# import datetime
#
#
# class Light(object):
#     def __init__(self):
#         self.enable = False
#
#     def open(self):
#         self.enable = True
#
#     def close(self):
#         self.enable = False
#
#     def is_open(self):
#         return self.enable
#
#
# class PointLight(Light):
#     def __str__(self):
#         return f"我是点光源"
#
#     def __init__(self, x, y):
#         super().__init__()
#         self.x = x
#         self.y = y
#
#     def show_point_light(self):
#         return f"我位于X:{self.x}  Y={self.y}"
#
#
# class SunLight(Light):
#     def __str__(self):
#         return f"我是太阳光"
#
#     def __init__(self, datetime):
#         super().__init__()
#         self.datetime = datetime
#
#     def date_sunlight(self):
#         return f"我是{self.datetime}点的太阳"
#
#
# pl = PointLight(250, 520)
# pl.show_point_light()
# print(pl, pl.show_point_light())
# sl = SunLight(datetime.datetime.now().hour)
# sl.date_sunlight()
# print(sl, sl.date_sunlight())


